package com.feiyuan.core.controller.admin;


import com.feiyuan.common.result.R;
import com.feiyuan.core.annotation.FeiyuanRequiresPermissions;
import com.feiyuan.core.pojo.entity.AdminMenu;
import com.feiyuan.core.service.AdminMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  菜单管理前端控制器
 * </p>
 *
 * @author Xupf
 * @since 2022-09-06
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping("/admin/core/menu")
//@CrossOrigin
public class AdminMenuController {

    @Autowired
    private AdminMenuService adminMenuService;

    @ApiOperation("查询菜单列表")
    @GetMapping("/list")
    @FeiyuanRequiresPermissions("admin:menu:list")
    public R list() {
        List<AdminMenu> menuDTOS = adminMenuService.selectMenus();
        return R.ok().data("menus", menuDTOS);
    }

    @ApiOperation("查询上级列表")
    @GetMapping("/upMenus")
    @FeiyuanRequiresPermissions("admin:menu:upMenus")
    public R upMenus() {
        List<AdminMenu> menus = adminMenuService.selectUpMenus();
        return R.ok().data("menus", menus);
    }

    @ApiOperation("查询详情")
    @GetMapping("/info/{id}")
    @FeiyuanRequiresPermissions("admin:menu:info")
    public R info(@PathVariable Long id) {
        return R.ok().data("info", adminMenuService.getById(id));
    }

    @ApiOperation("保存或者修改")
    @PostMapping("/saveOrUpdate")
    @FeiyuanRequiresPermissions("admin:menu:saveOrUpdate")
    public R saveOrUpdate(@RequestBody AdminMenu menu) {
        return R.ok().data("data", adminMenuService.saveOrUpdate(menu));
    }

    @ApiOperation("删除")
    @PostMapping("/remove/{id}")
    @FeiyuanRequiresPermissions("admin:menu:remove")
    public R remove(@PathVariable Long id) {
        return R.ok().data("data", adminMenuService.removeById(id));
    }
}

